package com.team.appinfo.service.impl;

import com.team.appinfo.entity.AppInfo;
import com.team.appinfo.entity.AppInfoConstant;
import com.team.appinfo.entity.AppVersion;
import com.team.appinfo.mapper.AppInfoMapper;
import com.team.appinfo.mapper.AppVersionMapper;
import com.team.appinfo.service.AppVersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class AppVersionServiceImpl implements AppVersionService {

   @Autowired
   private AppVersionMapper appVersionMapper;
   @Autowired
   private AppInfoMapper appInfoMapper;


    @Override
    public List<AppVersion> getAllVersionByAppId(Long id) {
        return appVersionMapper.getAllVersionByAppId(id);
    }

    @Override
    @Transactional
    public int addVersion(AppVersion appVersion) {    //添加时没有id,添加时自动增长
        //添加版本信息
       appVersionMapper.insertSelective(appVersion);
        //修改app信息的最新版
        AppInfo appinfo=new AppInfo();
        appinfo.setId(appVersion.getAppid()); //设置id  通过id修改
        appinfo.setVersionid(appVersion.getId());              //设置版本id
       appInfoMapper.updateByPrimaryKeySelective(appinfo);
        return 1;
    }

    @Override
    public AppVersion getLastVersionInfo(Long appid) {

        return appVersionMapper.getLastVersionInfo(appid);
    }
}
